<template>
  <!-- 账户明细对话框 -->
  <el-dialog
    title="账户明细"
    :visible.sync="openAccount"
    width="80%"
    append-to-body
  >
    <el-form
      :model="queryParams"
      ref="queryForm"
      label-width="80px"
      :inline="true"
    >
      <el-row>
        <el-form-item label="用户ID">
          <el-input v-model="form.userId" disabled style="width: 240px" />
        </el-form-item>
        <el-form-item label="用户名称">
          <el-input v-model="form.nickName" disabled style="width: 240px" />
        </el-form-item>
      </el-row>
      <el-form-item label="账户类型" prop="walletId">
        <el-select
          v-model="queryParams.walletId"
          placeholder="请选择账户类型"
          clearable
          filterable
          style="width: 240px"
        >
          <el-option
            v-for="(item, index) in walletList"
            :key="index"
            :label="item.walletName"
            :value="item.walletId"
          />
        </el-select>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          style="margin-left: 20px"
          >搜索</el-button
        >
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="walletFlowList">
      <el-table-column
        label="用户ID"
        align="center"
        prop="userId"
        width="200"
      />
      <el-table-column label="调整类型" align="center">
        <template slot-scope="scope">
          <div>{{ scope.row.incomeFlag ? "充值" : "划扣" }}</div>
        </template>
      </el-table-column>
      <el-table-column
        label="金额"
        align="center"
        prop="amount"
        :show-overflow-tooltip="true"
      />
      <el-table-column
        label="账户余额"
        align="center"
        prop="afterAmount"
        :show-overflow-tooltip="true"
      />
      <el-table-column label="账户类型" align="center">
        <template slot-scope="scope">
          <div v-for="(item, index) in walletList" :key="index">
            <div v-if="item.walletId == scope.row.walletId">
              {{ item.walletName }}
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="来源对象ID"
        align="center"
        prop="flowId"
        min-width="120"
      />
      <el-table-column
        label="备注"
        align="center"
        prop="remark"
        min-width="160"
      />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="100"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </el-dialog>
</template>

<script>
import { walletFlowList } from "@/api/customerWalletFlow/customerWalletFlow";

export default {
  name: "accountDetails",
  props: {
    form: Object,
    typeList: Array,
    walletList: Array,
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 是否显示弹出层
      openAccount: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        walletId: "",
        userId: "",
      },
      // 总条数
      total: 0,
      walletFlowList: [],
    };
  },
  watch: {
    form: {
      handler: function (val) {
        this.queryParams.userId = val.userId;
        this.queryParams.pageNo = 1;
        this.getList();
      },
      deep: true,
    },
  },
  methods: {
    // 查询流水列表
    getList() {
      this.queryParams.userId = this.form.userId;
      this.loading = true;
      walletFlowList(this.queryParams).then((response) => {
        this.walletFlowList = response.data.records || [];
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
  },
};
</script>
<style lang="scss" scoped>
/* 设置弹窗最大高度为500px */
::v-deep .el-dialog {
  display: flex;
  flex-direction: column;
  max-height: calc(100% - 150px);
}
::v-deep .el-dialog .el-dialog__body {
  flex: 1;
  overflow-y: auto;
}
</style>